﻿using System;
using System.Windows.Data;

namespace Finance.UI.Utils
{
    public class DatetimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is DateTime)
            {
                return ((DateTime)value).ToShortDateString();
            }
            throw new ArgumentException("Invalid data type, type of datetime is required.");
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is string)
            {
                return DateTime.Parse((string)value);
                throw new ArgumentException("Invalid data format, can't convert to datetime.");
            }
            throw new ArgumentException("Invalid data type, type of string is required.");
        }
    }
}
